package com.cmwa.scbp.sys.msg.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.cmwa.scbp.base.mvc.dao.BaseDao;
import com.cmwa.scbp.base.mvc.entity.Page;
import com.cmwa.scbp.base.mvc.entity.Result;
import com.cmwa.scbp.base.mvc.entity.SearchParam;
import com.cmwa.scbp.base.mvc.service.impl.BaseServiceImpl;
import com.cmwa.scbp.sys.msg.dao.IMsgConfDao;
import com.cmwa.scbp.sys.msg.service.IMsgConfService;
import com.cmwa.scbp.sys.msg.vo.MsgConfVo;

@Service
public class MsgConfServiceImpl extends BaseServiceImpl<MsgConfVo> implements IMsgConfService{
	@Resource
	private IMsgConfDao msgConfDao;
	
	@Override
	public BaseDao<MsgConfVo> getDao() {
		return msgConfDao;
	}
	
	@Override
	public MsgConfVo getMsgConf(String id) {
		return msgConfDao.getMsgConf(id);
	}

	@Override
	public int deleteMsgConf(String id) {
		return msgConfDao.deleteMsgConf(id);
	}

	@Override
	public Page<MsgConfVo> msgConfListPage(SearchParam sp) {
		List<MsgConfVo> items =msgConfDao.msgConfListPage(sp);
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}
	
	@Override
	public List<MsgConfVo> msgConfList(SearchParam sp) {
		List<MsgConfVo> items = msgConfDao.msgConfList(sp);
		return items;
	}

	@Override
	public int startConf(String id) {
		return msgConfDao.startConf(id);
	}

	@Override
	public int stopConf(String id) {
		return msgConfDao.stopConf(id);
	}
	@Override
	public void insertMsgConf(MsgConfVo vo){
		msgConfDao.insertMsgConf(vo);
	}

	@Override
	public String getSortNoBySendType(String sendType) {
		return msgConfDao.getSortNoBySendType(sendType);
	}

	@Override
	public Result<Object> validateMsgCodeIsExist(String msgCode, String oldMsgCode) {
		Result<Object> result = new Result<Object>();
		boolean success = true;
		if(StringUtils.isNotBlank(msgCode)) {
			int count = msgConfDao.countByMsgCode(msgCode, oldMsgCode);
			if(count != 0){
				success = false;
			}
		}else{
			success = false;
		}
		result.setSuccess(success);
		return result;
	}
}
